class Solution {
public:
    double findMaxAverage(vector<int>& nums, int k) {
        int body,pre,ans=INT_MIN;
        ans=body=accumulate(nums.begin(),nums.begin()+k,0);
        if(nums.size()==k){return (double)ans/k;}
        for(int i=k;i<nums.size();i++){
            pre=nums[i-k];
            body=body-pre+nums[i];
            ans=max(ans,body);
        }
        return (double)ans/k;
    }
};